﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using University.Workshop.DataAccess;
using System.Collections.ObjectModel;
using University.Workshop.Model;

namespace University.Workshop.WinApp
{
    public partial class RoomCheckout : TemplateForm
    {
        DateTime TodayDate;

        public RoomCheckout()
        {
            InitializeComponent();
        }

        private void RoomCheckout_Load(object sender, EventArgs e)
        {
            dataCheck.Rows.Clear();
            TodayDate = DateTime.Today;
            RoomStuffManager.GetAllTakenRooms(DateTime.Today,dataCheck); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataCheck.Rows.Clear();
            TodayDate = DateTime.Today;
            RoomStuffManager.GetAllTakenByName(DateTime.Today, dataCheck,textBox2.Text);
        }

        private void printInvoiceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!(dataCheck.Rows.Count - 1 >= 0) && !(dataCheck.SelectedRows.Count >= 1))
            {

                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBox.Show(this, "rows select is invalid", "Error", buttons, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
            }
            else
            {
                try
                {
                    DataGridViewCell selectUserName = dataCheck.CurrentRow.Cells["Client"];
                    RoomDataAccess room = new RoomDataAccess();
                    ProductRegister product = new ProductRegister();
                    room.Dispose();
                    room.InsertPayRoom(selectUserName.Value.ToString(), dataCheck.CurrentRow.Cells["Price"].Value.ToString());
                    Collection<Sale> sale = product.GetAllSaleClient(selectUserName.Value.ToString());
                    Invoice invoice = new Invoice(ClientManager.GetFullNameFromCI(selectUserName.Value.ToString()), selectUserName.Value.ToString(), dataCheck.CurrentRow.Cells["Price"].Value.ToString(), sale);
                    invoice.Show();
                    if (invoice.save)
                    {
                        room.DeleteCheckIn(selectUserName.Value.ToString());
                    }
                }
                catch (ArgumentException ar)
                {
                    MessageBox.Show(ar.Message);
                   
                }
               
            }
        }
    }
}
